<?php

declare (strict_types=1);
namespace App\Model;

use Hyperf\Database\Model\SoftDeletes;
/**
 * @property int $id 主键
 * @property int $mid 机构id
 * @property int $dept_id 关联部门
 * @property int $car_id 关联车辆
 * @property string $compulsory_insurance_no 强险单号
 * @property string $insurance_no 商业险单号
 * @property string $insurance_type 商业险类别
 * @property string $cost 费用
 * @property string $service_provider 保险服务商
 * @property string $start_time 起保时间
 * @property string $end_time 截止时间
 * @property int $insurance_status 保险状态
 * @property int $status 状态
 * @property string $remark 备注
 * @property int $created_user 创建人
 * @property \Carbon\Carbon $created_at 创建时间
 * @property \Carbon\Carbon $updated_at 更新时间
 * @property string $deleted_at 软删除字段
 */
class VehicleInsurance extends BaseModel
{
    use SoftDeletes;
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'vehicle_insurances';

    protected $hidden = ['deleted_at'];
    
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['id', 'mid', 'dept_id', 'car_id', 'toubao_time','status_name', 'compulsory_insurance_no', 'insurance_no', 'insurance_type', 'cost', 'service_provider','service_phone', 'start_time', 'end_time', 'insurance_status', 'status', 'remark', 'created_user', 'created_at', 'updated_at', 'deleted_at'];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'int', 'mid' => 'integer', 'dept_id' => 'integer', 'car_id' => 'integer', 'insurance_status' => 'integer', 'status' => 'integer', 'created_user' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];
    /**
     * @param  string  $value
     * @return void
     */
    public function setInsuranceTypeAttribute($value)
    {
        $this->attributes['insurance_type'] = implode(',',$value);
    }
    /**
     * @param  string  $value
     * @return void
     */
    public function getInsuranceTypeAttribute($value)
    {
        return explode(',', $value);
    }
    /**
     * [createuser 创建者]
     * @return [type] [description]
     */
    public function createuser()
    {
        return $this->hasOne(User::class, 'id', 'created_user');
    }
    /**
     * [vehicle 关联车辆]
     * @return [type] [description]
     */
    public function vehicle()
    {
        return $this->hasOne(Vehicle::class, 'id', 'car_id');
    }
    /**
     * [org 机构]
     * @return [type] [description]
     */
    public function org()
    {
        return $this->hasOne(Institution::class, 'id', 'mid');
    }
}